//package myschool.filter;
//
//import javax.servlet.*;
//import javax.servlet.annotation.WebFilter;
//import javax.servlet.annotation.WebInitParam;
//import javax.servlet.http.HttpServletRequest;
//import java.io.IOException;
//
///**
// * @author oldliu
// * @since 1.0
// */
////控制必须有Session中的对象，才允许访问，否则让去login.jsp
//@WebFilter(filterName = "role",value = "/*")
//@WebInitParam(name = "encoding",value = "utf-8")
//public class RoleFilter implements Filter {
//    @Override
//    public void init(FilterConfig filterConfig) throws ServletException {
//        String enc=filterConfig.getInitParameter("encoding");
//        System.out.println("enc,,,,"+enc);
//    }
//
//    @Override
//    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
//        System.out.println("进入了RoleFilter");
//
//        HttpServletRequest request= (HttpServletRequest) servletRequest;
//        String path=request.getServletPath();
//        if(path.equals("/doLoginServlet")||path.equals("/login.jsp")||path.endsWith(".css")){
//            filterChain.doFilter(servletRequest, servletResponse);
//            System.out.println("离开了RoleFilter");
//            return;
//        }
//        Object obj=request.getSession().getAttribute("USER_LOGIN");
//        if(obj==null){
//            request.setAttribute("tip","您还没有登录，不能访问【"+request.getServletPath()+"】");
//            request.getRequestDispatcher("/login.jsp").forward(request,servletResponse);
//            System.out.println("离开了RoleFilter");
//            return;
//        }
//        filterChain.doFilter(servletRequest, servletResponse);
//        System.out.println("离开了RoleFilter");
//    }
//
//    @Override
//    public void destroy() {
//
//    }
//}
